package src.CodeTopSecondPractice;

public class _160 {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if (headA == null || headB == null)
            return null;
        // 双链表遍历指针
        ListNode cur1 = headA, cur2 = headB;
        // 双指针遍历链表
        while (cur1 != cur2) {
            cur1 = cur1 != null ? cur1.next : headB;
            cur2 = cur2 != null ? cur2.next : headA;
        }
        return cur1;
    }
}
